﻿function deleteMessageCommon(mid, url, confirmMessage, removedMessage, sender)
{
    if (confirm(confirmMessage.replace('{0}', mid)))
    {
        $.post(url, { mid: mid }, function (data)
        {
            $("#msg" + mid + " > div.msgBody").html("<p class=\"removed\">" + removedMessage + "</p>");
            alert(removedMessage);
            if (sender)
            {
                $(sender).closest("li").remove();
            }
        });
    }
    return false;
}
function preventMultipleSubmit() {
    $(this).submit(function() {
        return false;
    });
    return true;
}
function postAndContinue(sender, data, confirmMessage)
{
	if ((!confirmMessage) || confirm(confirmMessage))
	{
		data.__RequestVerificationToken = $("input[name='__RequestVerificationToken']").val();
		$.post($(sender).attr("href"), data, function(responseData){
			if (responseData && responseData.nextUrl)
			{
				document.location.href = responseData.nextUrl;
			}
			else
			{
				window.location.reload();
			}
		});
	}
	return false;
}

function html_encode(str) {
    var s = "";
    if (str.length == 0) return "";
    s = str.replace(/&/g, "&amp;");
    s = str.replace(/&amp;amp;/g, "&amp;");
    s = s.replace(/</g, "&lt;"); s = s.replace(/>/g, "&gt;");
    s = s.replace(/ /g, "&nbsp;"); s = s.replace(/\'/g, "&#39;");
    s = s.replace(/\"/g, "&quot;");
    return s;
}
function html_decode(str) {
    var s = "";
    if (str.length == 0) return "";
    s = str.replace(/&amp;/g, "&");
    s = s.replace(/&lt;/g, "<");
    s = s.replace(/&gt;/g, ">");
    s = s.replace(/&nbsp;/g, " ");
    s = s.replace(/&#39;/g, "\'");
    s = s.replace(/&quot;/g, "\"");
    return s;
};

//jQuery Dialog的信息提示，指定ID显示
function AlertDialog(id, dialogwidth, dialogheight) {
    $("#" + id).dialog({
        resizable: false,
        modal: true,
        closeOnEscape: true,
        closeText: "hide",
        position: 'center',
        show: 'fade',
        hide: 'fade',
        width: dialogwidth,
        height: dialogheight,
        close: function () {
        },
        buttons: {
            确定: function () {
                $(this).dialog("close");
            }
        }
    });
    return;
}

function DisplayEditButton(o) {
    $(o.lastChild.previousSibling.lastChild.previousSibling.previousSibling.previousSibling.lastChild.previousSibling).show();
}

function HideEditButton(o) {
    $(o.lastChild.previousSibling.lastChild.previousSibling.previousSibling.previousSibling.lastChild.previousSibling).hide();
}

function toggle_collapse(objname) {
    var obj = $("#" + objname);
    if (obj) {
        obj.slideToggle("2000");
    }
    var img = $("#" + objname + '_img');
    if (img) {
        if (img.attr("src") == AC_ROOT_DIR + "/images/Common/collapsed_yes.gif") {
            img.attr("src", AC_ROOT_DIR + "/images/Common/collapsed_no.gif");
        }
        else {
            img.attr("src", AC_ROOT_DIR + "/images/Common/collapsed_yes.gif");

        }
    }
}
